package com.wh.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.mchange.v2.c3p0.impl.DefaultConnectionTester;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * @Auther: HuiEr
 * @Date: 2020/2/26 22:18
 * @Description
 */
public class UtilsC3p0 {

   public static ComboPooledDataSource dataSource;

   static {
       dataSource=new ComboPooledDataSource();
       try {
           dataSource.setDriverClass("com.mysql.jdbc.Driver");
           dataSource.setJdbcUrl("jdbc:mysql:///test");
           dataSource.setUser("root");
           dataSource.setPassword("root");
       } catch (PropertyVetoException e) {
           e.printStackTrace();
       }
   }

   public static QueryRunner getQueryRunner(){
       return new QueryRunner(dataSource);
   }
}
